/*
 * This file is part of Catfish.
 * Copyright (C) 2010 Namazu Studios LLC
 * 
 * Catfish is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 3 of 
 * the License, or (at your option) any later version.
 * 
 * Catfish is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with Catfish.  If not, please visit:
 *  
 * http://www.gnu.org/licenses/
 *  
 */
package com.namazustudios.catfish.generator;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.Key;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.namazustudios.catfish.Catfish;
import com.namazustudios.catfish.annotation.Name;

@Singleton
@Name(name="incremental")
public class IncrementalIdentityGenerator implements IdentityGenerator<Object> {

	@Inject
	private DatastoreService datastore;

	@Inject
	private Catfish catfish;

	@Override
	public Key generateId(Object object) {
		String kind = catfish.getKind(object);
		return datastore.allocateIds(kind, 1).getStart();
	}

	@Override
	public Key generateId(Key parent, Object object) {
		String kind = catfish.getKind(object);
		return datastore.allocateIds(parent, kind, 1).getStart();
	}

}
